package com.code.day20;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Demo06FileReader {
    public static void main(String[] args) throws IOException {
//        method();
        method1();
    }


    /**
     * int read() 一次读一个字符,返回的是读取的字符
     */
    public  static  void method() throws IOException {
        FileReader fileReader = new FileReader("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo3.txt");
        int len =0;
        while((len = fileReader.read())!=-1){
            System.out.print((char)len);
        }
        fileReader.close();
    }
    /**
     * int read(char[] cbuf) 一次读多个字符,返回的是读取的字符个数
     */
    public static  void method1() throws IOException {
        FileReader fileReader = new FileReader("D:\\java-code\\java-full-stack\\01-java-base\\src\\com\\code\\day20\\file\\demo3.txt");
        char[] chars = new char[1024];
        int len= 0;
        while((len=fileReader.read(chars))!=-1){
            System.out.print(new String(chars,0,len));
        }
    }
}
